/*
 * @Descripttion: 
 * @version: 
 * @Author: 高月飞
 * @Date: 2023-11-18 08:06:27
 * @LastEditors: 高月飞
 * @LastEditTime: 2023-11-18 08:47:12
 */
import axios from "axios"
import request from "./Interceptors/request";
import response from "./Interceptors/response";

//接口泛型来完成对于所有请求返回值的二次封装
export interface IApiRoot<T> {
    code: number;
    msg: string
    data: T
}

//创建网络请求
const instances = axios.create()

request(instances)
response(instances)

/**
 * POST
 * @param url 请求url地址
 * @param data 请求体数据
 * @param config 请求的配置--额外请求
 * @returns  Promise<T>
 */

export const post = <T>(url: string, data: any, config: any = {}) => instances.post<any, IApiRoot<T>>(url, data, config);


/**
 * GET
 * @param url 请求url地址
 * @param config 请求的配置--额外请求
 * @returns Promise<T>
 */
export const get = <T>(url: string, config: any = {}) => instances.get<any, IApiRoot<T>>(url, config);

/**
 * Put请求
 * @param url 请求的url地址
 * @param data 请求体数据
 * @param config 请求配置 -- 额外请求
 * @returns Promise<T> 
 */
export const put = <T>(url: string, data: any, config = {}) => instances.put<any, IApiRoot<T>>(url, data, config)


/**
 * delete请求
 * @param {string} url 请求的url地址
 * @param {object} config 请求的额外头信息
 * @returns Promise<any>
 */
export const del = <T>(url, config = {}) => instances.delete<any, IApiRoot>(url, config)